<?php
$config = include_once('../public/config/config.php');
include_once('../public/func/db.php');
include_once('../public/func/upload.func.php');
if($_POST['repwd'] != $_POST['pwd']){
	echo '<script>alert("两次密码不一致");window.location.href=history.go(-1)</script>';die;
}
$array = array(
	'uname' => '用户名',
	'pwd' => '密码',
	'nickname' => '昵称',
	'email' => '邮箱',
);
foreach($_POST as $k=>$v){
	if(!$v){
		echo '<script>alert("'.$array[$k].'不能为空");window.location.href=history.go(-1);</script>';die;
	}
}
$post = $_POST;
unset($post['repwd']);
if($_FILES['pic']['error'] != 4){
	$path = '../public/upload';
	$post['pic'] = upload($_FILES['pic'],$path);
}else{
	$post['pic'] = 'default.jpg';
}
$table = 'user';
$post['ctime'] = time();
$post['pwd'] = md5($_POST['pwd']);
$res = insert($config,$table,$post);
if($res == ''){
	echo '<script>alert("注册成功");window.location.href="/home/login.php"</script>';
}else{
	echo '<script>alert("注册失败");window.location.href=history.go(-1);</script>';
}
